package com.chenfan.finance.controller;

import com.chenfan.finance.commons.Response;
import com.chenfan.finance.commons.ResponseCode;
import com.chenfan.finance.model.TocCharge;
import com.chenfan.finance.model.dto.TocChargeQuery;
import com.chenfan.finance.service.impl.TocImportDataService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author liran
 */
@Api(tags = "流水导入")
@Slf4j
@RestController
public class TocImportDataController {
    @Autowired
    private TocImportDataService importDataService;


    /**
     * 导入原始单据
     */
    @PostMapping(value = "importData")
    public Response<Object> importData(@RequestParam("files") MultipartFile[] files,@RequestParam("lasts") MultipartFile[] lasts) throws Exception {
        List<Map<String, String>> maps = importDataService.impotData(files,lasts);
        return new Response<>(ResponseCode.SUCCESS, maps);
    }


    /**
     * 汇总数据
     */
    @GetMapping(value = "sumMonthData")
    public Response<Object> sumMonthData(String shop) {
        importDataService.sumMonthData(shop);
        return new Response<>(ResponseCode.SUCCESS);
    }

    /**
     * reference
     */
    @GetMapping(value = "reference")
    public Response<Object> reference(int t) {
        return new Response<>(ResponseCode.SUCCESS, importDataService.reference(t));
    }


    /**
     * createCharge
     */
    @PostMapping(value = "createCharge")
    public Response<Object> createCharge(@RequestBody TocChargeQuery query) {
        importDataService.saveTocCharge(query);
        return new Response<>(ResponseCode.SUCCESS);
    }

    /**
     * tocChargePageInfo
     */
    @PostMapping(value = "tocChargePageInfo")
    public Response<Object> tocChargePageInfo(@RequestBody TocChargeQuery query) {
        PageInfo<TocCharge> tocChargePageInfo = importDataService.tocChargePageInfo(query);
        return new Response<>(ResponseCode.SUCCESS, tocChargePageInfo);
    }
}
